<?php
namespace Home\Controller;
use Think\Controller;
class InfoController extends CommonController {
	//老师详细信息
    public function laoshi_info()
    {
        //公共显示变量
        $this->public_xianshi();

        $id = I('get.id');
        $this->assign('id',$id);
        $city = I('get.newcity');
        $sql = "select t1.id,t1.sfz_name,t1.education,t1.school,t1.major,t1.face,t1.sfz_img,t1.jiaoshizheng_img,t1.qitazheng_img,t1.create_time,
        				t2.jiaoling,t2.jianjie,t2.start_year,t2.start_month,t2.stop_year,t2.stop_month,t2.experience,t2.stu_stye,t2.laoshi_stye,
        				t3.grades,t3.class,t3.price,t3.subject,t3.address,t3.methods,t3.shouke_time
        				from laoshi_user as t1 inner join jiaoling_jli as t2 on t1.id=t2.uid inner join showke_info as t3 on t1.id=t3.uid 
        				where t1.id={$id} and t1.city='{$city}' and is_shenhe_xs=1 and is_dongjie=1 and is_del=0";
        $laoshi_info = M()->query($sql);
        $this->assign('laoshi_info',current($laoshi_info));

        //上门方式 匹配对应ID跟name显示
        $method = M('teachingmethod')->select();
        $this->assign('method',$method);

        //授课时间段显示 上午
        $showke_time_sw = M('showke_time')->where(array('time_name'=>'上午'))->select();
        $this->assign('showke_time_sw',$showke_time_sw);
        //授课时间段显示 下午
        $showke_time_xw = M('showke_time')->where(array('time_name'=>'下午'))->select();
        $this->assign('showke_time_xw',$showke_time_xw);
        //授课时间段显示 晚上
        $showke_time_ws = M('showke_time')->where(array('time_name'=>'晚上'))->select();
        $this->assign('showke_time_ws',$showke_time_ws);

        //$showke_info[0]['shouke_time']转数组
        $laoshi_infos = explode(',', $laoshi_info[0]['shouke_time']);
        $this->assign('laoshi_infos',$laoshi_infos);


        //学生总数
        $stu_count = M('jz_to_ls_yuyue')->where(array('ls_uid'=>$id))->count();
        $this->assign('stu_count',$stu_count);
        //总课时
        $laoshi_zong_ks = M('jz_to_ls_yuyue')->where(array('ls_uid'=>$id))->sum('zong_ks');
        $this->assign('laoshi_zong_ks',$laoshi_zong_ks);
        

        //成功案例
        $cases = M('success_case')->where(array('uid'=>$id))->select();
        $this->assign('cases',$cases);

        //我的课程
        $sql = "select t1.id,t1.grade,t1.zong_ks,t2.name from jz_to_ls_yuyue as t1 inner join jiazhang_xuqiu as t2 on t1.jz_uid=t2.uid where ls_uid='{$id}' and is_shenhe=1";
        $my_kcs = M()->query($sql);
        $this->assign('my_kcs',$my_kcs);


        $this->display();
    }

    //家长 预定 老师 提交页面
    public function jz_order_ls()
    {
        //公共显示变量
        $this->public_xianshi();


        //检测是否登陆
        if (!isset($_SESSION['id'])) {
            $this->redirect('user/login');
        }

        //查找老师个人信息
        $id = I('get.id');
        $this->assign('ls_id',$id);

        $sql = "select t1.sfz_name,t1.city,t2.class,t2.grades,t2.subject from laoshi_user t1 inner join showke_info t2 on t1.id=t2.uid where t1.id='{$id}'";
        $laoshi_info = M()->query($sql);
        $this->assign('laoshi_info',current($laoshi_info));

        //根据老师城市 查找其下区域
        $cityid = M('city')->where(array('city_name'=>$laoshi_info[0]['city']))->getField('cityid');
        $city_quyu = M('city')->where(array('parent_id'=>$cityid))->select();
        $this->assign('city_quyu',$city_quyu);

        $this->display();
    }

    //家长 预定 老师 提交
    public function jz_order_ls_add()
    {
        if (IS_POST) {
            $data['jz_uid'] = $_SESSION['id'];
            $data['ls_uid'] = I('post.ls_id');

            $date = I('post.year').'-'.I('post.month').'-'.I('post.date');
            $data['date'] = $date;
            $data['time'] = I('post.shi');

            $data['city_quyu'] = I('post.city_quyu');
            $data['subject'] = I('post.ls_subject');
            $data['grade'] = I('post.ls_grades');
            $data['class'] = I('post.ls_class');

            $data['stu_situation'] = I('post.paiming');
            $data['beizhu'] = I('post.content');

            //入库 家长预约老师/约课表
            $res = M('jz_to_ls_yuyue')->add($data);
            if ($res) {
                $url = U('jiazhang/index');
                 $arr = array(
                        'error' =>1,
                        'info'=>"添加成功",
                        'url' => $url
                        );
                echo json_encode($arr);
            }else {
                 $arr = array(
                        'error' =>0,
                        'info'=>"添加失败"
                        );
                echo json_encode($arr);
            }

        }

    }







}